package com.example.lenovo.demo.view.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.lenovo.demo.R;


/**
 * Created by Lenovo on 2016/12/14.
 */
public class ImageButtonwithText extends LinearLayout implements View.OnClickListener{
    private ImageView imageView;
    private TextView textView;
    private int wid=60,hei=60;
    private Context context;


    public ImageButtonwithText(Context context) {
        super(context);



        imageView=new ImageView(context);
        imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,0,4));
        imageView.setPadding(25,25,25,25);
        textView=new TextView(context);
        textView.setGravity(android.view.Gravity.CENTER_HORIZONTAL);
        textView.setPadding(0, 5, 0, 0);
        textView.setTextSize(13);
        textView.setSingleLine();
        textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        textView.setEllipsize(TextUtils.TruncateAt.END);
        textView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,0,2));
        setClickable(true);
        setFocusable(true);
        setPadding(0,5,0,0);
        setOrientation(LinearLayout.VERTICAL);
        addView(imageView);
        addView(textView);
    }
    public void setClick(OnClickListener listener)
    {
        imageView.setOnClickListener(listener);
    }
    public void setText(CharSequence buttonText) {
        textView.setText(buttonText);
    }
    public void setImageBitmap(Bitmap bitmap){
        imageView.setImageBitmap(bitmap);
    }


    @Override
    public void onClick(View v) {

    }
    public void setWH(int w,int h){
        this.wid=w;
        this.hei=h;
    }
    public void setTags(String path){
        imageView.setTag(path);
    }
    public String getTags(){
        return (String) imageView.getTag();
    }
    public void setTextViewFont(int size){
        textView.setTextSize(size);
    }
    public void setTextViewG(){
        setGravity(Gravity.CENTER_HORIZONTAL);
    }
    public ImageView getImageView(){
        return imageView;
    }

}
